﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.AndonManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.AndonManagement.AndonStationHeaderVMs
{
    public partial class AndonStationHeaderListVM : BasePagedListVM<AndonStationHeader_View, AndonStationHeaderSearcher>
    {
        
        protected override IEnumerable<IGridColumn<AndonStationHeader_View>> InitGridHeader()
        {
            return new List<GridColumn<AndonStationHeader_View>>{
                
                this.MakeGridHeader(x => x.AndonStationHeader_Station).SetTitle(@Localizer["Page.关联站点"].Value),
                this.MakeGridHeader(x => x.AndonStationHeader_HeaderRole).SetTitle(@Localizer["Page.职位"].Value),
                this.MakeGridHeader(x => x.AndonStationHeader_Header).SetTitle(@Localizer["Page.负责人"].Value),
                this.MakeGridHeader(x => x.AndonStationHeader_ContactNumber).SetTitle(@Localizer["Page.联系电话"].Value),
                this.MakeGridHeader(x => x.AndonStationHeader_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.AndonStationHeader_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.AndonStationHeader_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.AndonStationHeader_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<AndonStationHeader_View> GetSearchQuery()
        {
            var query = DC.Set<AndonStationHeader>()
                
                .CheckEqual(Searcher.StationId, x=>x.StationId)
                .CheckContain(Searcher.HeaderRole, x=>x.HeaderRole)
                .CheckContain(Searcher.Header, x=>x.Header)
                .CheckEqual(Searcher.ContactNumber, x=>x.ContactNumber)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new AndonStationHeader_View
                {
				    ID = x.ID,
                    
                    AndonStationHeader_Station = x.Station.TenantCode,
                    AndonStationHeader_HeaderRole = x.HeaderRole,
                    AndonStationHeader_Header = x.Header,
                    AndonStationHeader_ContactNumber = x.ContactNumber,
                    AndonStationHeader_CreateTime = x.CreateTime,
                    AndonStationHeader_UpdateTime = x.UpdateTime,
                    AndonStationHeader_CreateBy = x.CreateBy,
                    AndonStationHeader_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class AndonStationHeader_View: AndonStationHeader
    {
        
        public string AndonStationHeader_Station { get; set; }
        public string AndonStationHeader_HeaderRole { get; set; }
        public string AndonStationHeader_Header { get; set; }
        public string AndonStationHeader_ContactNumber { get; set; }
        public DateTime? AndonStationHeader_CreateTime { get; set; }
        public DateTime? AndonStationHeader_UpdateTime { get; set; }
        public string AndonStationHeader_CreateBy { get; set; }
        public string AndonStationHeader_UpdateBy { get; set; }

    }

}